package com.ruoyi.web.service.impl;

import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.web.domain.Book;
import com.ruoyi.web.mapper.BookMapper;
import com.ruoyi.web.service.FileService;
import com.ruoyi.web.service.IBookService;
import com.ruoyi.web.utils.UserMsgUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * bookService业务层处理
 *
 * @author ruoyi
 * @date 2024-04-26
 */
@Service
public class BookServiceImpl implements IBookService {
    @Autowired
    private BookMapper bookMapper;
    @Autowired
    private FileService fileService;

    /**
     * 查询book
     *
     * @param id book主键
     * @return book
     */
    @Override
    public Book selectBookById(Long id) {
        return bookMapper.selectBookById(id);
    }

    /**
     * 查询book中的所有image
     *
     * @return image集合
     */
    public List<String> selectAllImages() {
        return bookMapper.selectAllImages();
    }

    /**
     * 查询book列表
     *
     * @param book book
     * @return book
     */
    @Override
    public List<Book> selectBookList(Book book) {
        List<Book> bookList = bookMapper.selectBookList(book);
        return bookList;
    }

    /**
     * 查询book列表
     *
     * @param book book
     * @return book
     */
    @Override
    public List<Book> selectBookListAll(Book book) {
        List<Book> bookList = bookMapper.selectBookList(book);
        bookList = bookList.stream().peek(item -> {
            item.setAudio(UserMsgUtil.subAvatar(item.getAudio()+"3"));
        }).collect(Collectors.toList());
        return bookList;
    }

    /**
     * 新增book
     *
     * @param book book
     * @return 结果
     */
    @Override
    public int insertBook(Book book) {
        return bookMapper.insertBook(book);
    }

    /**
     * 修改book
     *
     * @param book book
     * @return 结果
     */
    @Override
    public int updateBook(Book book) {
        return bookMapper.updateBook(book);
    }

    /**
     * 批量删除book
     *
     * @param ids 需要删除的book主键
     * @return 结果
     */
    @Override
    public int deleteBookByIds(Long[] ids) {
        return bookMapper.deleteBookByIds(ids);
    }

    /**
     * 删除book信息
     *
     * @param id book主键
     * @return 结果
     */
    @Override
    public int deleteBookById(Long id) {
        return bookMapper.deleteBookById(id);
    }
}
